﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.IO;
using SNSComponent.SNSProvider;

namespace SNSComponent.LocalData
{
    internal static class LocalDataProvider
    {
        private const string FILE_PATH = "SNSComponent\\";

        public static void Save(Stream authInfo, string providerName)
        {
            string fileName = providerName.ToString().GetHashCode().ToString() + ".date";
            Utiltiy.FileUtility.SaveFile(FILE_PATH + fileName, authInfo);

        }

        public static Stream Read(string providerName)
        {
            string fileName = providerName.GetHashCode().ToString() + ".date";

            return  Utiltiy.FileUtility.ReadFile(FILE_PATH+fileName, (stream) =>
                {
                    if (stream != null)
                    {
                        Stream result = new MemoryStream();
                        stream.CopyTo(result);
                        return result;
                    }
                    else return null;
                });
        }

        public static void DeleteFile(string providerName)
        {
            string fileName = providerName.GetHashCode().ToString() + ".txt";

            Utiltiy.FileUtility.DeleteFile(FILE_PATH+fileName);
        }
    }


}
